package com.wonders.ghy.juc.cas;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * 1 CAS是什么? ==> compareAndSet
 *   比较并交换
 **/
public class CasDemo {
    public static void main(String[] args) {
        AtomicInteger atomicInteger = new AtomicInteger(5);
        // main do thing......
        System.out.println(atomicInteger.compareAndSet(5, 2019)+"\tcurrent data "+atomicInteger.get());
        System.out.println(atomicInteger.compareAndSet(5, 1024)+"\tcurrent data "+atomicInteger.get());
        atomicInteger.getAndIncrement();
    }
}
